/**
 * 小球类
 */

class Ball{
  constructor(props) {
    this.x = 0
    this.y = 0
    this.r = 20
    this.vx = 0
    this.vy = 0
    this.scaleX = 1
    this.scaleY = 1
    this.strokeStyle = 'rgba(0, 0, 0, 0)'
    this.fillStyle = 'rgb(57, 119, 224)'
    this.alpha = 1
    this.shadowColor = 'rgba(0, 0, 0, 0)'
    this.shadowBlur = 0
    this.shadowOffsetX = 0
    this.shadowOffsetY = 0
    Object.assign(this, props)
    return this
  }

  render(ctx) {
    const {x, y, r, scaleX, scaleY, fillStyle, strokeStyle, alpha, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY} = this
    ctx.save()
    ctx.translate(x, y)
    ctx.scale(scaleX, scaleY)
    ctx.strokeStyle = strokeStyle
    ctx.fillStyle = fillStyle
    ctx.globalAlpha = alpha
    ctx.shadowColor = shadowColor
    ctx.shadowBlur = shadowBlur
    ctx.shadowOffsetX = shadowOffsetX
    ctx.shadowOffsetY = shadowOffsetY
    ctx.beginPath()
    ctx.arc(0, 0, r, 0, 2 * Math.PI)
    ctx.fill()
    ctx.stroke()
    ctx.restore()
    return this
  }

  isPoint(pos) {
    let {x, y} = pos
    return this.r >= Math.sqrt((x - this.x) ** 2 + (y - this.y) ** 2)
  }
}
